package imoney.server;

import imoney.server.util.DataStoreManager;
import imoney.shared.*;
import imoney.shared.model.MoneyTransaction;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class TransactionServelt extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
		
		// TRANSACTIONs CREATION      (montant, intitul, payer, beneficiaires)
		ArrayList<Integer> benefs = new ArrayList<Integer>();
		benefs.add(0);
		benefs.add(1);
		benefs.add(2);
		benefs.add(3);
		
		ArrayList<Double> repart = new ArrayList<Double>();
		repart.add((double)5);
		repart.add((double)15);
		repart.add((double)1);
		repart.add((double)19);

		try {
			MoneyTransaction transac = new MoneyTransaction(666,"boutou",117,benefs, repart);
			DataStoreManager.registerAndMakePersistent(transac);
		}
		catch (Exception ex){
			System.err.println(ex.getLocalizedMessage());
		}
		
		List<String> liste = DataStoreManager.get5lastTransacs();
		resp.getWriter().write("<head><meta http-equiv='Content-Type' content='text/html; charset='ISO'>" +
				"<title>5 Last Transactions</title></head>" +
				"<p>Page d'affichage temporaire de l'historique des transaction d'argent<br/>");
		for (int i=0; i<liste.size(); i++){
			resp.getWriter().write("<br/>"+liste.get(i));
		}
	}
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
		resp.getWriter().write("doPost ? what do you mean by that ");
	}
	}
